package com.cloudlinkin.util;

import org.apache.log4j.Logger;

import java.util.StringTokenizer;


/*
 * 短信机 精分日志 工具类
 */
public class BizUtils {
	private static final Logger submitLog = Logger.getLogger("hfx_sms_submit_biz");

	public static void setSubmitLog(String msg) {
		submitLog.info(msg);
	}

	public static String keyWordsToReplace(String content) {

		if (content.indexOf("\"") != -1) {

			StringBuilder sb = new StringBuilder();

			StringTokenizer tokenizer = new StringTokenizer(content, "\"", true);

			int num = tokenizer.countTokens();

			for (int i = 0; i < num; i++) {
				String temp = tokenizer.nextToken();
				if (temp.indexOf("\"") != -1) {
					sb.append("\"");
				}
				sb.append(temp);
			}
			content = sb.toString();
		}

		StringBuilder sb = new StringBuilder("\"");

		if ((content.indexOf("\r") != -1) || (content.indexOf("\n") != -1) || (content.indexOf("\r\n") != -1)) {
			StringTokenizer tokenizer = new StringTokenizer("\r\n");
			int num = tokenizer.countTokens();

			for (int i = 0; i < num; i++) {
				sb.append(tokenizer.nextToken());
			}
		} else {
			sb.append(content);
		}
		sb.append("\"");
		return sb.toString();
	}
}
